#include <math.h>
#include <stdlib.h>
#include "score_calcu.h"
#include "../pdb_index/xyz.h"
#include "query_result.h"
#include "../bulk_storage/bulk_storage.h"

double score_calcu(struct store * qr_store, int aa_serial,const off_t start, const off_t stop){

  int i, j, num;
  double score;
  struct q_data * qd;
  struct q_result * qr;
  
  qd = malloc((stop-start+1)*sizeof(struct q_data));
 
  for(i = start,j=0; i<=stop; i++,j++){
    qr = store_read(qr_stroe,i);
    qd[j]->distance = qr->q_distance;
    qd[j]->x = qr->h_xyz->x;
    qd[j]->y = qr->h_xyz->y;
    qd[j]->z = qr->h_xyz->z;
    if(qr->q_serial == aa_serial)
      num = j;
    store_release(qr,i);
  }
  
  for(i=0;i<j;i++){
    if(i != num){
      score += ((1/qd[i]->distance)/sqrt((qd[i]->x - qd[num]->x)*(qd[i]->x - qd[num]->x)+(qd[i]->y - qd[num]->y)*(qd[i]->y - qd[num]->y)+(qd[i]->z - qd[num]->z)*(qd[i]->z - qd[num]->z)));
    }
  }
  free(qd);
  return(score);
}

      
